package com.zjbti.work36;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    public void query(int id) {
        MyHelper myHelper = new MyHelper(getApplicationContext());
        SQLiteDatabase db = myHelper.getWritableDatabase();
        Cursor cursor = db.query("information", null, "_id?", new String[]{id + ""}, null, null, null, null);
        if (cursor.getCount() != 0) {
            while (cursor.moveToNext()) {
                @SuppressLint("Range") String _id = cursor.getString(cursor.getColumnIndex("_id"));
                @SuppressLint("Range") String account = cursor.getString(cursor.getColumnIndex("account"));
                @SuppressLint("Range") String password = cursor.getString(cursor.getColumnIndex("password"));
            }
        }
        cursor.close();
        db.close();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyHelper myHelper = new MyHelper(getApplicationContext());
        myHelper.getWritableDatabase();
        SQLiteDatabase db = myHelper.getWritableDatabase();
        ContentValues values = new ContentValues();


        values.put("account", "小明");
        values.put("password", "it938495");
        long id = db.insert("information", null, values);
        db.close();
    }
}